*******************************************************************************
* Load and append data sets
*******************************************************************************

use dataset_gallup, clear
append using dataset_anes
append using dataset_gss

*******************************************************************************
* Keep only if non-missing on party subsets
*******************************************************************************

keep if (data == "anes" & !mi(ftDem)) | ///
	(data == "gallup" & !mi(confidenceDem)) | ///
	(data == "gss" & !mi(spend_lawenfDem))

*******************************************************************************
* Figure
*******************************************************************************

foreach y in confidence ft spend_lawenf {
	
	local mytext1 text(0.74 1997 "Rep")
	local mytext2 text(0.44 1997 "Dem")

	if "`y'" != "confidence" local mytext1
	if "`y'" != "confidence" local mytext2
	
	if "`y'" == "confidence" local mytitle "(a) Confidence (Gallup)"
	if "`y'" == "ft" local mytitle "(b) Feeling thermometer (ANES)"
	if "`y'" == "spend_lawenf" local mytitle "(c) Spending (GSS)"

	#delimit;

	gr tw
		(sc `y'Repu year, col(black) msym(Oh) msize(medsmall))
		(sc `y'Dem year, col(black) msym(O) msize(medsmall))
		(lfit `y'Repu year, col(black))
		(lfit `y'Dem year, col(black) lpat(dash))
		, 	
			ylab(, angle(horiz))
			legend(off)
			plotregion(style(none))
			ytitle("")
			xtitle("")
			xlab(1960(10)2020)
			`mytext1'
			`mytext2'
			name(g`y'L, replace)
			title("By party")
			;
			
	#delimit cr

	gr close

	#delimit;

	gr tw
		(sc `y'RepDem year, col(black) msize(medsmall))
		(lfit `y'RepDem year, col(black))
		, 	
			ylab(, angle(horiz))
			legend(off)
			plotregion(style(none))
			ytitle("")
			xtitle("")
			xlab(1960(10)2020)
			name(g`y'R, replace)
			title("Rep-Dem gap")
			;
			
	#delimit cr

	gr close

	gr combine g`y'L g`y'R, name(g`y', replace) title("`mytitle'")

	gr close

}

gr combine gconfidence gft gspend_lawenf, cols(1) imargin(zero) ///
	ysize(3) xsize(3)

*******************************************************************************
* Export
*******************************************************************************

gr export "_output/figure3.eps", replace

*******************************************************************************
* End
*******************************************************************************
